<?php
 

 $filepath = rtrim($_POST['filepath'],'/').'/';
 $content  = $_POST['data'];
 $cat_id   = $_POST['cat_id'];
 $filename = md5($cat_id);
 $savefile = $filepath.$filename;
 if(!is_dir($filepath)){
    $old = umask(0);
    mkdir($filepath,0777,true);
    umask($old);
  }

 if(!file_exists($savefile)) touch($savefile);

 $length = strlen($content);
 $fp =fopen($savefile,'w');
 flock($fp,LOCK_SH);
    if(!$status=fwrite($fp,$content,$length)){
        usleep(500);
        $status=fwrite($fp,$content,$length);
    }
 flock($fp,LOCK_UN);
 if($status){
    echo 1;exit;
 }else{
    echo 2;exit;
 }
?>
